<?php
session_start();
function __autoload($class_name) {
    include '../class/' . $class_name . '.php';
}
?>
<?php include("functions.php"); ?>
<?php include("connection.php"); ?>
<?php $settings = new Settings(); ?>
<?php

	if(isset($_POST['userName']) && isset($_POST['userTeam']) && isset($_POST['userPassword'])) {
		
		$params = "";
		
		$user = new User(0);
		$user->ime = $_POST['userName'];
		$user->imeTima = $_POST['userTeam'];
		$user->setSifra($_POST['userPassword']);
		
		if (!($user->userExists())) {
			$user->insertIntoDb();
			
			$fuser = new FantasyUser($user->getNewUserID());
			$fuser->generateRandomTeam();
			$fuser->insertTeamIntoDb($settings->currentRound);
			
			$user->logIn($_POST['userName'], $_POST['userPassword']);
		}
		else {
			$params = "1";
		}
	}
	
	header("Location: ". $settings->base ."games/" . $params);
	
?>